package io;

import java.io.File;
import java.util.Scanner;

public class FileSearch {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String path, name;
        System.out.println("请输入查询路径：");
        path = in.nextLine();
        System.out.println("请输入查询文件：");
        name = in.nextLine();
        searchFile(new File(path), name);
    }

    private static void searchFile(File file, String name) {
        if (!file.exists()) return;
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files == null) return;
            for (File f : files) {
                searchFile(f, name);
            }
        } else {
            String fileName = file.getName();
            if (fileName.contains(name)) {
                System.out.println(file.getAbsolutePath());
            }
        }
    }
}
